#ifndef PUDGE_GRFX_TEST_HPP
#define PUDGE_GRFX_TEST_HPP

#include <pudge/grfx/render.hpp>
#include <pudge/math/vec.hpp>

namespace pudge{ namespace grfx{ 

	struct render_test_1_
	{
		struct position_traits
		{
			typedef pudge::math::vec<3,float> value_type;
			typedef STATIC_DRAW usage_type;
		};
		struct index_traits
		{
			typedef unsigned long value_type;
			typedef STATIC_DRAW usage_type;
			typedef QUADS poly_type;
		};
		template<class IStream, class PStream>
		void operator()(IStream & is, PStream & ps) const
		{
			is << 0 << 1 << 2 << 3;
			
			pudge::math::vec<3,float> pos(0.0f, 0.0f, 0.0f);
			ps << pos;
			pos.x = 0.5f;	ps << pos;
			pos.y = -0.5f; 	ps << pos;
			pos.x = 0.0f; 	ps << pos;
		}
		void operator()() const
		{
			std::string vertex_shader_src
				(	"in vec3 position; "
				"	void main()"
				"	{"
				"		vec4 pos = vec4(position,1.0); "
				"		pos.y += .5; "
				"		gl_Position = pos;"
				"	}" );

			std::string frag_shader_src
				(	"out vec4 out_color;"
				"	void main()"
				"	{"
				"		out_color = vec4(0.0,1.0,0.0,1.0); "
				"	}" );
	
			vertex_shader vshad (vertex_shader_src, string_tag);
			frag_shader fshad (frag_shader_src, string_tag);
			shader_program prog;

			bind_attribute(prog, std::string("position"));
			bind_shader(prog,vshad);
			bind_shader(prog,fshad);
			link_program(prog);
			use_program(prog);

			vertex_attribute<position_traits> positions;
			index_attribute<index_traits> indices;

			cache_attributes(indices, positions, *this, 4, 4);
			render_attributes(4, indices, positions);
			decache_attribute(indices);
			decache_attribute(positions);
		}
	} const render_test_1;

	void render_test()
	{
		render_test_1();
	}
}}
#endif